//
//  HotCityTableViewCell.m
//  TodatPlay
//
//  Created by dllo on 16/9/20.
//  Copyright © 2016年 DM.C. All rights reserved.
//

#import "HotCityTableViewCell.h"
#import "CityCollectionViewCell.h"
#import "City.h"
#import "TAMacro.h"

@interface HotCityTableViewCell ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
@property (weak, nonatomic) IBOutlet UICollectionView *hotCityCollectionVIew;
@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *hotCityFlowLayout;
@property (nonatomic, strong) NSArray *cityArr;
@end

@implementation HotCityTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.hotCityCollectionVIew.delegate = self;
    self.hotCityCollectionVIew.dataSource = self;
    [self.hotCityCollectionVIew registerNib:[UINib nibWithNibName:@"CityCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"reuse"];
    _cityArr = [NSArray array];
    [self handleData];
    
    self.hotCityFlowLayout.sectionInset = UIEdgeInsetsMake(5, 10, 5, 30);
    self.hotCityFlowLayout.minimumLineSpacing = 5;
    self.hotCityFlowLayout.minimumInteritemSpacing = 5;
    
}
- (void)handleData {
    City *beijing = [[City alloc] initWithCityName:@"北京" postCode:110000];
    City *tianjin = [[City alloc] initWithCityName:@"天津" postCode:120000];
    City *shenyang = [[City alloc] initWithCityName:@"沈阳" postCode:210100];
    City *shanghai = [[City alloc] initWithCityName:@"上海" postCode:310000];
    City *nanjing = [[City alloc] initWithCityName:@"南京" postCode:320100];
    City *hangzhou = [[City alloc] initWithCityName:@"杭州" postCode:330100];
    City *wuhan = [[City alloc] initWithCityName:@"武汉" postCode:420100];
    City *changsha = [[City alloc] initWithCityName:@"长沙" postCode:430100];
    City *guangzhou = [[City alloc] initWithCityName:@"广州" postCode:440100];
    City *shenzhen = [[City alloc] initWithCityName:@"深圳" postCode:440300];
    City *chongqing = [[City alloc] initWithCityName:@"重庆" postCode:500000];
    City *chengdu = [[City alloc] initWithCityName:@"成都" postCode:510100];
    _cityArr = @[beijing, tianjin, shenyang, shanghai, nanjing, hangzhou, wuhan, changsha, guangzhou, shenzhen, chongqing, chengdu];
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _cityArr.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    CityCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    City *city = _cityArr[indexPath.row];
    cell.titleLabel.text = city.city_name;
    return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return CGSizeMake((SCREEN_WIDTH - 80) / 4.0, 30);
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
